<?php

namespace app\model\agency;

use app\base\BaseModel;
use app\libs\Util;
use think\model\concern\SoftDelete;

/**
 * 模型-agency_title
 * Class agency_title
 * @package app\model
 */
class AgencyArticleModel extends BaseModel
{
    use SoftDelete;

    protected $name = 'agency_article';

    /**
     * 还原数据
     * @param $id
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function backData($id)
    {
        $self_obj = self::onlyTrashed()->find($id);
        $this->setRedis($self_obj->toArray());
        if ($self_obj['status'] == 1) {
            $this->redis->zAdd($this->redis_key . ':rank', $self_obj['rank'], $self_obj['id']);
        }
        return $self_obj->restore();
    }

    /**
     * 获取文章列表
     * @param string $keyword
     * @param $page
     * @param $limit
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getDataList($keyword = '', $page, $limit)
    {
        $map['status'] = 1;
        if (!empty($keyword)) {
            $map['like'] = ['title' => $keyword];
        }
        $data_list = $this->getPageList($map, 'sort desc', $page, $limit, "*");
        return $data_list['dataList'];
    }
}
